﻿// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
#nullable disable
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using WpfApp1.Services;

namespace WpfApp1.Models
{
    /// <summary>
    /// Модель, описывающая отзыв пользователя к купленному товару.
    /// </summary>
    public partial class Reviews : INotifyPropertyChanged, ICopied<Reviews>
    {
        public event PropertyChangedEventHandler PropertyChanged;
        public void OnPropertyChanged([CallerMemberName] string prop = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(prop));
        }

        public Reviews Clone()
        {
            Reviews review = new Reviews();
            review.OrderId = OrderId;
            review.Order = Order;
            review.ReviewText = ReviewText;
            review.Stars = Stars;
            review.CreatedAt = CreatedAt;
            review.Order = Order;
            review.Images = new ObservableCollection<ReviewImage>(Images);
            return review;
        }

        public Reviews()
        {
            Images = new ObservableCollection<ReviewImage>();
        }

        public void Copy(Reviews review)
        {
            OrderId = review.OrderId;
            Order = review.Order;
            ReviewText = review.ReviewText;
            review.Stars = Stars;
            review.CreatedAt = CreatedAt;
            Order = review.Order;
            Images = review.Images;
        }

        private int _orderId;
        public int OrderId 
        {
            get => _orderId;
            set
            {
                _orderId = value;
                Order = OrderService.GetOrderByOrderId(_orderId);
                OnPropertyChanged();
                
            }
        }
        public string ReviewText { get; set; }
        public int Stars { get; set; }
        public DateTime CreatedAt { get; set; }

        private Orders _order;
        public virtual Orders Order
        { 
            get => _order;
            set
            {
                _order = value;
                OnPropertyChanged();
            }
        }

        public virtual ObservableCollection<ReviewImage> Images { get; set; }
    }
}